package com.kwedding.handler;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.apache.ibatis.type.BaseTypeHandler;
import org.apache.ibatis.type.JdbcType;
import org.springframework.context.annotation.Configuration;

import springfox.documentation.spring.web.json.Json;
@Configuration
public class JsonHandler extends BaseTypeHandler<Json> {

	@Override
	public void setNonNullParameter(PreparedStatement ps, int i, Json parameter, JdbcType jdbcType)
			throws SQLException {
		ps.setString(i, parameter.value());
	}

	@Override
	public Json getNullableResult(ResultSet rs, String columnName) throws SQLException {
		return new Json(rs.getString(columnName));
	}

	@Override
	public Json getNullableResult(ResultSet rs, int columnIndex) throws SQLException {
		return new Json(rs.getString(columnIndex));
	}

	@Override
	public Json getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
		return new Json(cs.getString(columnIndex));
	}

}